Answer:

' Convert grams to kilograms
'
PRINT "Enter number of grams" 
INPUT GRAMS
PRINT "Number of kilograms:", GRAMS / 1000
END

Since each kilogram is 1000 grams, the number of grams is divided by 1000 to get the number of kilograms.

Prompting the User

Say the above program were run and that the user entered 734 grams. The monitor would look like:

Enter number of grams
? 734
Number of kilograms:    0.734

The string "Enter number of grams" is called a prompt. A prompt is a short phrase which tells the user of a computer program what is expected. The program is said to prompt the user for input.

You should be careful that the prompt makes sense to the user of a program. The prompt is for the user; it doesn't "tell" the INPUT statement what to do. Here is a poorly written version of the "grams to kilograms" program:

' Convert grams to kilograms
PRINT "Enter number" 
INPUT GRAMS
PRINT "result:", GRAMS / 1000
END

When this program is run, and the user enters data as before, the user sees:

Enter number
? 734
result:    0.734

The answer is correct, and Mr. Spock might be happy with the program (since "logically" the two programs are the same). But the second version is not user-friendly and is prone to user error. Maybe the user though the program was converting ounces to pounds. Nothing on the monitor would correct this mistaken notion.

QUESTION 10:

Write a program which converts OUNCES to POUNDS. The program should write an informative prompt to the user, INPUT the number of ounces, then write the number of pounds.

Click here for a .